var Dog = require('./dog.js')

var dog1 = new Dog('taidi', 5);
var dog2 = new Dog('zangao', 6)

dog1.on('bark', function () {
    console.log(this.name + ' bark!! enery:' + this.energy);
})

var clearId1 = setInterval(() => {
    dog1.emit('bark')
    if (dog1.energy > 1) {
        dog1.energy--;
    }
    else {
        clearInterval(clearId1)
    }
}, 1000);

dog2.on('bark', function () {
    console.log(this.name + ' bark!! enery:' + this.energy);
})

var clearId2 = setInterval(() => {
    dog2.emit('bark')
    if (dog2.energy > 1) {
        dog2.energy--;
    }
    else {
        clearInterval(clearId2)
    }
}, 1000);


